<template>
  <div class="gl_heightFull">
    <div class="demo-input-suffix gl_searchBox">
      <el-row :gutter="20">
        <el-col :md="4" :lg="4">
          <p>账号状态</p>
          <el-select v-model="IsEnabled" size="mini" @change="getList()">
            <el-option label="全部" value="" />
            <el-option label="启用" :value="true" />
            <el-option label="停用" :value="false" />
          </el-select>
        </el-col>
        <el-col :md="4" :lg="4">
          <p>姓名</p>
          <el-input v-model="Api_GET_ClubBranchBranchStudentListQO.StudentName" placeholder="请输入姓名" size="mini" clearable @change="getList()" />
        </el-col>
        <el-col :md="4" :lg="4">
          <p>手机号码</p>
          <el-input v-model="Api_GET_ClubBranchBranchStudentListQO.PhoneNumber" placeholder="请输入手机号" size="mini" clearable @change="getList()" />
        </el-col>
        <el-col :md="4" :lg="4">
          <p>所在班级</p>
          <el-input v-model="Api_GET_ClubBranchBranchStudentListQO.ClassName" placeholder="请输入班级名称" size="mini" clearable @change="getList()" />
        </el-col>
        <el-col :md="4" :lg="4">
          <p>教练</p>
          <el-input v-model="Api_GET_ClubBranchBranchStudentListQO.CoachName" placeholder="请输入教练姓名" size="mini" clearable @change="getList()" />
        </el-col>
        <el-col :md="4" :lg="4">
          <el-button type="primary" style="margin-top:25px" size="mini" @change="getList()">筛选</el-button>
          <el-button type="warning" size="mini" @click="reset()">{{ $t('button.Reset') }}</el-button>
        </el-col>
      </el-row>
    </div>
    <div style="margin-top:15px">
      <el-table v-loading="tableLoading" class="gl_table_noBorder" size="mini" :data="tableData">
        <el-table-column label="姓名" align="center" prop="name" />
        <el-table-column label="联系方式" align="center">
          <template slot-scope="{row}">
            <span v-for="(item,index) in row.studentContacts " :key="index">
              {{ item.phoneNumber }} {{ row.studentContacts .length > 0 ? row.studentContacts .length - 1 === index ? '': '/' : '' }}
            </span>
          </template>
        </el-table-column>
        <el-table-column label="卡种">
          <template slot-scope="{ row }">
            <span v-for="(item,index) in row.studentMembershipCards" :key="index">
              {{ item.name }} {{ row.studentMembershipCards.length > 0 ? row.studentMembershipCards.length - 1 === index ? '': '/' : '' }}
            </span>
          </template>
        </el-table-column>
        <el-table-column label="所在班级">
          <template slot-scope="{row}">
            <span v-for="(item,index) in row.classStudents" :key="index">
              {{ item.class.name }} {{ row.classStudents.length > 0 ? row.classStudents.length - 1 === index ? '': '/' : '' }}
            </span>
          </template>
        </el-table-column>
        <el-table-column label="教练">
          <template slot-scope="{row}">
            <span v-for="(item,index) in row.studentCoachs" :key="index">
              {{ item.employee.name }} {{ row.studentCoachs.length > 0 ? row.studentCoachs.length - 1 === index ? '': '/' : '' }}
            </span>
          </template>
        </el-table-column>
        <el-table-column label="状态">
          <template slot-scope="{row}">
            <div v-if="row.isEnable === true"><i class="success_circle" />已启用</div>
            <div v-else><i class="error_circle" />已停用</div>
          </template>
        </el-table-column>
        <el-table-column label="操作" width="160">
          <template slot-scope="{ row }">
            <el-button size="mini" type="text" @click="topersonal(row)">查看</el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <!-- 分页 -->
    <el-row class="gl_pt_15" style="text-align: right;">
      <el-pagination
        :current-page="Api_GET_ClubBranchBranchStudentListQO.Page"
        :page-size="Api_GET_ClubBranchBranchStudentListQO.MaxResultCount"
        :total="totalPage"
        layout="total,sizes,prev,pager,next,jumper"
        :page-sizes="[10, 20, 30, 40]"
        @size-change="sizeChange"
        @current-change="pageIndexChange"
      />
    </el-row>
  </div>
</template>

<script>
import { api_GET_ClubBranchBranchStudentList } from '@/extend/api/hallswaggerApi/app.js';
import { Api_GET_ClubBranchBranchStudentListQO } from '@/lib/form/hall/swaggerForm';
export default {
  data() {
    return {
      Api_GET_ClubBranchBranchStudentListQO: new Api_GET_ClubBranchBranchStudentListQO(), // 学员列表
      totalPage: 0,
      tableData: [],
      tableLoading: false,
      IsEnabled: '',
      currentPage: 1
    };
  },
  created() {
    this.getList();
  },
  methods: {
    // 获取学员列表
    getList(page) {
      this.tableLoading = true;
      this.Api_GET_ClubBranchBranchStudentListQO.IncludeStudentContacts = true;
      this.Api_GET_ClubBranchBranchStudentListQO.IncludeStudentCoachs = true;
      this.Api_GET_ClubBranchBranchStudentListQO.IncludeClassStudents = true;
      this.Api_GET_ClubBranchBranchStudentListQO.IncludeStudentMembershipCards = true;
      this.Api_GET_ClubBranchBranchStudentListQO.IsEnable = this.IsEnabled;
      this.Api_GET_ClubBranchBranchStudentListQO.BranchId = this.$parent.$parent.$parent.branchid;
      this.Api_GET_ClubBranchBranchStudentListQO.Page = page || 1;
      this.Api_GET_ClubBranchBranchStudentListQO.SkipCount = (this.Api_GET_ClubBranchBranchStudentListQO.Page - 1) * this.Api_GET_ClubBranchBranchStudentListQO.MaxResultCount;
      api_GET_ClubBranchBranchStudentList(this.Api_GET_ClubBranchBranchStudentListQO).then(res => {
        this.tableLoading = false;
        this.tableData = res.items;
        this.totalPage = res.totalCount;
        this.$parent.$parent.$parent.tabList[1].label = '学员(' + res.totalCount + ')';
      }, error => {
        this.tableLoading = false;
        const _msg = error.error.message || error.message;
        this.$message({ type: 'error', message: _msg });
      });
    },
    // 重置按钮
    reset () {
      this.Api_GET_ClubBranchBranchStudentListQO = new Api_GET_ClubBranchBranchStudentListQO();
      this.IsEnabled = '';
      this.getList();
    },
    // 分页按钮
    sizeChange(MaxResultCount) {
      this.Api_GET_ClubBranchBranchStudentListQO.MaxResultCount = MaxResultCount;
      this.getList();
    },
    pageIndexChange(currentPage) {
      this.getList(currentPage);
    },
    // 跳转查看列表
    topersonal(row) {
      this.$router.push({ name: 'Personal', query: { 'rid': row.registerId, 'id': row.id, 'branchid': this.$parent.$parent.$parent.branchid }});
    }
  }
};
</script>

<style scoped>
.success_circle {
  display: inline-block;
  margin-right: 8px;
  width: 6px;
  height: 6px;
  background: #14CE67;
  border-radius: 50%;
}
.error_circle {
  display: inline-block;
  margin-right: 8px;
  width: 6px;
  height: 6px;
  background: #FF3434;
  border-radius: 50%;
}
</style>
